﻿Public Class FrmCashBill
    Public FOpentype As String
    Private FPInfo As New BServer.FBillPrintCFG
    Private FBInfo As New BServer.FBillCash
    Public FBid As String
    Private Sub FrmCashBill_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Icon = My.Resources.Properties
        '--获取打印参数
        SControl._Base_GetBillPrintConfig(UInfo.FSession, "Cash", FPInfo, "")
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)

        Select Case FOpentype
            Case "NewBill"
                NewBill()
                FPrintBTN.Enabled = False
            Case "View"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBillInfo() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If
                '-预留
                If FBInfo.FVid = Nothing Then
                    '-没审核
                    FSaveBox.Text = "收费"
                    FSaveBox.Image = My.Resources.money
                    FPrintBTN.Enabled = False
                ElseIf FBInfo.FVid = UInfo.id Then
                    FSaveBox.Enabled = False
                    FPrintBTN.Enabled = True
                Else
                    '--其它人的单据
                    FSaveBox.Enabled = False
                    FPrintBTN.Enabled = False
                End If
            Case "Modify"
                '--取单据信息
                If FBid Is Nothing Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If CInt(FBid) <= 0 Then
                    MsgBox("参数错误")
                    Dispose()
                    Return
                End If
                If GetBillInfo() = False Then
                    MsgBox("读取单据信息失败!")
                    Dispose()
                    Return
                End If

                If FBInfo.FUid <> UInfo.id Then
                    CHGControls(False)
                    MsgBox("不能修改他人填制的单据")
                    Dispose()
                    Return
                End If
                FSaveBox.Enabled = True
                FPrintBTN.Enabled = False
                CHGControls(True)
            Case Else
                MsgBox("参数错误")
                Dispose()
                Return
        End Select
    End Sub
    Private Function GetBillInfo() As Boolean
        Try
            FBInfo = New BServer.FBillCash
            FBInfo.id = FBid
            Dim ErrString As String = String.Empty
            If SControl._BILL_Cash_GetBillInfo(UInfo.FSession, FBInfo.id, "", FBInfo, ErrString) = False Then
                MsgBox(ErrString)
                Return False
            End If
            CHGControls(False)
            FNameBox.Text = FBInfo.FCustom.FName
            FCNameBox.Text = FBInfo.FCustom.FCName
            FBillNoBox.Text = FBInfo.FBillNo
            FVerifyBox.Text = FBInfo.FVerifyCode
            FSummaryBox.Text = FBInfo.FSummary
            FAmountBox.Value = FBInfo.FAmount
            FMarkBox.Text = FBInfo.FMark
            FMakerBox.Text = FBInfo.FUName
            FVermanBox.Text = FBInfo.FVName
            FAmountBigBox.Text = FControl.MoneyToUpper(FBInfo.FAmount)
            FDateBox.Value = FBInfo.FDate
            Label1.Text = "打印次数:" & FBInfo.FPCount
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
    Private Sub ButtonX5_Click(sender As Object, e As EventArgs) Handles ButtonX5.Click
        '--读取参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        '--显示页面设置窗口
        PageSetupDialog1.ShowDialog()
        '--保存参数
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        '---------参数赋值
        FPInfo.FMarginB = ps.Margins.Bottom
        FPInfo.FMarginT = ps.Margins.Top
        FPInfo.FMarginR = ps.Margins.Right
        FPInfo.FMarginL = ps.Margins.Left
        If ps.Landscape = False Then
            FPInfo.FPaperDirect = "V"
        Else
            FPInfo.FPaperDirect = "H"
        End If
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Cash", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
    End Sub

    Private Sub ButtonX4_Click(sender As Object, e As EventArgs) Handles FPrintBTN.Click

        '--读取打印参数
        FControl.PSToPageSettings(PageSetupDialog1, FPInfo)
        Dim ps As New System.Drawing.Printing.PageSettings
        ps = PageSetupDialog1.PageSettings
        PrintDialog1.PrinterSettings = ps.PrinterSettings
        '--弹出打印设置窗口
        If PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
            Return
        End If
        '--更新打印参数
        PrintDialog1.AllowPrintToFile = False
        ps.PrinterSettings = PrintDialog1.PrinterSettings
        '--保存打印参数
        FPInfo.FPaperName = ps.PaperSize.PaperName
        FPInfo.FPrinterName = ps.PrinterSettings.PrinterName
        '---上传参数
        Dim ErrString As String = String.Empty
        If SControl._Base_SetBillConfig(UInfo.FSession, "Cash", FPInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        '--增加打印次数
        If SControl._Bill_Cash_AddPrintCount(UInfo.FSession, FBInfo, ErrString) = False Then
            MsgBox(ErrString)
            Return
        End If
        Label1.Text = "打印次数:" & FBInfo.FPCount
        '---显示预览
        PrintDocument1.DefaultPageSettings = ps
        PrintDocument1.DocumentName = "收款收据(二)"
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
        '--增加打印次数
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Try
            '--打印设置
            '--A4纸
            PrintDocument1.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize With {.PaperName = "A4", .Height = 1169, .Width = 827}
            '--页面设置
            PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
            '--打印机设置
            PrintDocument1.PrinterSettings = PrintDialog1.PrinterSettings
            '--设置以1/100英寸为单位
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            '--定义变量
            Dim g As Graphics = e.Graphics
            Dim FX As Integer = FPInfo.FMarginL
            Dim FY As Integer = FPInfo.FMarginR
            Dim fnt As Font = New Font("宋体", 20)
            Dim rect As Rectangle = Nothing
            '--绘制表格
            '-标题下方两条直线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.2 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(8.2 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(9.5 + FY))
            '-主单据框
            rect = New Rectangle(New Point(FControl.CalcInch(27 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(150), FControl.CalcInch(40)))
            g.DrawRectangle(Pens.Black, rect)
            '-格线
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(41 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(41 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(48 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(54 + FX), FControl.CalcInch(48 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(73.5 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(73.5 + FX), FControl.CalcInch(48 + FY))
            '--单据头
            g.PageUnit = GraphicsUnit.Millimeter
            '-标题
            fnt = New Font("宋体", 20)
            g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, New PointF(88 + FX, 0 + FY))
            '-日期
            fnt = New Font("宋体", 12)
            '-单据头
            g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, New PointF(85 + FX, 11 + FY))
            g.DrawString("交款单位: " & FNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 17.5 + FY))
            g.DrawString("交 款 人: " & FCNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 24 + FY))
            g.DrawString("编  号: " & FBillNoBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 17.5 + FY))
            g.DrawString("验证码: " & FVerifyBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 24 + FY))
            '-事由
            g.DrawString("交款事由:", fnt, Brushes.Black, New PointF(28 + FX, 30 + FY))
            g.DrawString(FSummaryBox.Text.Trim, fnt, Brushes.Black, 56 + FX, 30 + FY)
            '-交款金额
            g.DrawString("交款金额", fnt, Brushes.Black, 32 + FX, 40 + FY)
            g.DrawString("小写", fnt, Brushes.Black, 56 + FX, 37 + FY)
            g.DrawString("￥" & FAmountBox.Value, fnt, Brushes.Black, 75 + FX, 37 + FY)
            g.DrawString("大写", fnt, Brushes.Black, 56 + FX, 43 + FY)
            g.DrawString(FAmountBigBox.Text.Trim, fnt, Brushes.Black, 75 + FX, 43 + FY)
            '-备注
            g.DrawString("备注:", fnt, Brushes.Black, 28 + FX, 50 + FY)
            g.DrawString(FMarkBox.Text, fnt, Brushes.Black, 28 + FX, 55 + FY)
            '--表尾
            g.DrawString(String.Format("收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 28 + FX, 70 + FY)
            'g.DrawString("收款人签章:", fnt, Brushes.Black, 74 + FX, 70 + FY)
            'g.DrawString("开票人:" & FMakerBox.Text.Trim, fnt, Brushes.Black, 112 + FX, 70 + FY)
            g.DrawString("①", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
            g.DrawString("记", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
            g.DrawString("账", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
            g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
            '----------------------第一段结束--------------------------------

            FY += 90
            '--绘制表格
            '-标题下方两条直线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.5 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(8.5 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(9.5 + FY))
            '-主单据框
            rect = New Rectangle(New Point(FControl.CalcInch(27 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(150), FControl.CalcInch(40)))
            g.DrawRectangle(Pens.Black, rect)
            '-格线
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(41 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(41 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(48 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(54 + FX), FControl.CalcInch(48 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(73.5 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(73.5 + FX), FControl.CalcInch(48 + FY))
            '--单据头
            g.PageUnit = GraphicsUnit.Millimeter
            '-标题
            fnt = New Font("宋体", 20)
            g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, New PointF(88 + FX, 0 + FY))
            '-日期
            fnt = New Font("宋体", 12)
            '-单据头
            g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, New PointF(85.5 + FX, 11 + FY))
            g.DrawString("交款单位: " & FNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 17.5 + FY))
            g.DrawString("交 款 人: " & FCNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 24 + FY))
            g.DrawString("编  号: " & FBillNoBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 17.5 + FY))
            g.DrawString("验证码: " & FVerifyBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 24 + FY))
            '-事由
            g.DrawString("交款事由:", fnt, Brushes.Black, New PointF(28 + FX, 30 + FY))
            g.DrawString(FSummaryBox.Text.Trim, fnt, Brushes.Black, 56 + FX, 30 + FY)
            '-交款金额
            g.DrawString("交款金额", fnt, Brushes.Black, 32 + FX, 40 + FY)
            g.DrawString("小写", fnt, Brushes.Black, 56 + FX, 37 + FY)
            g.DrawString("￥" & FAmountBox.Value, fnt, Brushes.Black, 75 + FX, 37 + FY)
            g.DrawString("大写", fnt, Brushes.Black, 56 + FX, 43 + FY)
            g.DrawString(FAmountBigBox.Text.Trim, fnt, Brushes.Black, 75 + FX, 43 + FY)
            '-备注
            g.DrawString("备注:", fnt, Brushes.Black, 28 + FX, 50 + FY)
            g.DrawString(FMarkBox.Text, fnt, Brushes.Black, 28 + FX, 55 + FY)
            '--表尾
            g.DrawString(String.Format("收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 28 + FX, 70 + FY)
            g.DrawString("②", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
            g.DrawString("客", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
            g.DrawString("户", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
            g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
            '----------第二段结束----------------

            FY += 90
            '--绘制表格
            '-标题下方两条直线
            g.PageUnit = GraphicsUnit.Display
            g.DrawLine(New Pen(Brushes.Black, 4), FControl.CalcInch(80 + FX), FControl.CalcInch(8.5 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(8.5 + FY))
            g.DrawLine(New Pen(Brushes.Black, 1), FControl.CalcInch(80 + FX), FControl.CalcInch(9.5 + FY), FControl.CalcInch(132 + FX), FControl.CalcInch(9.5 + FY))
            '-主单据框
            rect = New Rectangle(New Point(FControl.CalcInch(27 + FX), FControl.CalcInch(28 + FY)), New Size(FControl.CalcInch(150), FControl.CalcInch(40)))
            g.DrawRectangle(Pens.Black, rect)
            '-格线
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(35 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(41 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(41 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(27 + FX), FControl.CalcInch(48 + FY), FControl.CalcInch(177 + FX), FControl.CalcInch(48 + FY))
            '-竖线
            g.DrawLine(Pens.Black, FControl.CalcInch(54 + FX), FControl.CalcInch(28 + FY), FControl.CalcInch(54 + FX), FControl.CalcInch(48 + FY))
            g.DrawLine(Pens.Black, FControl.CalcInch(73.5 + FX), FControl.CalcInch(35 + FY), FControl.CalcInch(73.5 + FX), FControl.CalcInch(48 + FY))
            '--单据头
            g.PageUnit = GraphicsUnit.Millimeter
            '-标题
            fnt = New Font("宋体", 20)
            g.DrawString(FCaptionLabel.Text.Trim, fnt, Brushes.Black, New PointF(88 + FX, 0 + FY))
            '-日期
            fnt = New Font("宋体", 12)
            '-单据头
            g.DrawString("日期: " & FDateBox.Value.ToString("yyyy年MM月dd日"), fnt, Brushes.Black, New PointF(85 + FX, 11 + FY))
            g.DrawString("交款单位: " & FNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 17.5 + FY))
            g.DrawString("交 款 人: " & FCNameBox.Text.Trim, fnt, Brushes.Black, New PointF(28 + FX, 24 + FY))
            g.DrawString("编  号: " & FBillNoBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 17.5 + FY))
            g.DrawString("验证码: " & FVerifyBox.Text.Trim, fnt, Brushes.Black, New PointF(118 + FX, 24 + FY))
            '-事由
            g.DrawString("交款事由:", fnt, Brushes.Black, New PointF(28 + FX, 30 + FY))
            g.DrawString(FSummaryBox.Text.Trim, fnt, Brushes.Black, 56 + FX, 30 + FY)
            '-交款金额
            g.DrawString("交款金额", fnt, Brushes.Black, 32 + FX, 40 + FY)
            g.DrawString("小写", fnt, Brushes.Black, 56 + FX, 37 + FY)
            g.DrawString("￥" & FAmountBox.Value, fnt, Brushes.Black, 75 + FX, 37 + FY)
            g.DrawString("大写", fnt, Brushes.Black, 56 + FX, 43 + FY)
            g.DrawString(FAmountBigBox.Text.Trim, fnt, Brushes.Black, 75 + FX, 43 + FY)
            '-备注
            g.DrawString("备注:", fnt, Brushes.Black, 28 + FX, 50 + FY)
            g.DrawString(FMarkBox.Text, fnt, Brushes.Black, 28 + FX, 55 + FY)
            '--表尾
            g.DrawString(String.Format("收款人签章:     开票人:{0}   收款单位:{1}", FMakerBox.Text, SControl.Base_Org_getOrgName(FBInfo.FOrgid)), fnt, Brushes.Black, 28 + FX, 70 + FY)
            g.DrawString("③", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 37 + FY})
            g.DrawString("其", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 43 + FY})
            g.DrawString("它", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 48 + FY})
            g.DrawString("联", fnt, Brushes.Black, New PointF With {.X = 179 + FX, .Y = 53 + FY})
        Catch ex As Exception
            MsgBox(String.Format("绘制打印模板失败!{0}错误信息:{1}", vbCrLf, ex.Message))
            e.Cancel = True
        End Try

    End Sub

    Private Sub ButtonX3_Click(sender As Object, e As EventArgs) Handles ButtonX3.Click
        Dispose()
    End Sub

#Region "设置控件状态"
    Public Sub CHGControls(ByVal FStat As Boolean)
        FDateBox.Enabled = FStat
        FNameBox.Enabled = FStat
        FCNameBox.Enabled = FStat
        FSummaryBox.Enabled = FStat
        FAmountBox.Enabled = FStat
        FMarkBox.Enabled = FStat
    End Sub

#End Region
#Region "新单据"
    Private Sub NewBill()
        CHGControls(True)
        FDateBox.Value = Now
        GetCustomList()
        GetSummaryList()
        FAmountBox.Value = 0
        FMarkBox.Text = String.Empty
        FMakerBox.Text = String.Empty
        FVermanBox.Text = String.Empty
        FBillNoBox.Text = String.Empty
        FVerifyBox.Text = String.Empty
    End Sub
#End Region
#Region "获取客户列表"
    Private Sub GetCustomList()
        Try
            FNameBox.DataSource = Nothing
            FCNameBox.DataSource = Nothing
            Dim TmpArr As Byte() = Nothing
            Dim ds As DataSet = Nothing
            Dim ErrString As String = String.Empty
            If SControl._BILL_Cash_GetBaseList(UInfo.FSession, "Custom", "*", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox("无法解析返回数据!")
                Return
            End If
           
            FCNameBox.DataSource = ds.Tables(0)
            FCNameBox.ValueMember = "id"
            FCNameBox.DisplayMember = "FCName"

            FNameBox.DataSource = ds.Tables(0).Copy
            FNameBox.ValueMember = "id"
            FNameBox.DisplayMember = "FName"
            FNameBox.SelectedIndex = -1
            FCNameBox.SelectedIndex = -1
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
#End Region
#Region "获取摘要列表"
    Private Sub GetSummaryList()
        Try
            FSummaryBox.DataSource = Nothing
            Dim TmpArr As Byte() = Nothing
            Dim ds As DataSet = Nothing
            Dim ErrString As String = String.Empty
            If SControl._BILL_Cash_GetBaseList(UInfo.FSession, "Summary", "*", TmpArr, ErrString) = False Then
                MsgBox(ErrString)
                Return
            End If
            If FControl.DsRestore(ds, TmpArr) = False Then
                MsgBox("无法解析返回数据!")
                Return
            End If
            FSummaryBox.DataSource = ds.Tables(0).DefaultView
            FSummaryBox.DisplayMember = "FSummary"
            FSummaryBox.ValueMember = "id"
            FSummaryBox.SelectedIndex = -1
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
#End Region

    Private Sub ButtonX1_Click(sender As Object, e As EventArgs) Handles ButtonX1.Click
        NewBill()
    End Sub

    Private Sub ButtonX2_Click(sender As Object, e As EventArgs) Handles FSaveBox.Click
        SaveBill()
    End Sub
#Region "保存单据"
    Private Sub SaveBill()
        Try
            Dim ErrString As String = String.Empty
            If FBInfo Is Nothing Or FBInfo.id = Nothing Or FOpentype = "Modify" Then
                If FDateBox.Value = Nothing Then
                    MsgBox("日期不能为空!")
                    Return
                End If
                If FNameBox.Text = String.Empty Then
                    MsgBox("交款单位不能为空")
                    Return
                End If
                If FSummaryBox.Text = String.Empty Then
                    MsgBox("交款事由不能为空!")
                    Return
                End If
                '--结构
                If FOpentype <> "Modify" Then
                    FBInfo = New BServer.FBillCash
                End If
                FBInfo.FCustom = New BServer.FBaseCash
                '--客户名
                Dim s As Integer = FNameBox.FindStringExact(FNameBox.Text)
                If s >= 0 Then
                    FNameBox.SelectedIndex = s
                    FBInfo.FCustom.id = FNameBox.SelectedValue
                Else
                    FBInfo.FCustom.id = -1
                End If
                FBInfo.FCustom.FName = FNameBox.Text
                FBInfo.FCustom.FCName = FCNameBox.Text
                FBInfo.FSummary = FSummaryBox.Text
                FBInfo.FAmount = FAmountBox.Value
                FBInfo.FMark = FMarkBox.Text
                FBInfo.FUid = UInfo.id
                FBInfo.FUName = UInfo.FRName
                FBInfo.FDate = FDateBox.Value
                If FOpentype = "Modify" Then
                    '--修改
                    If SControl._BILL_Cash_ModifyBill(UInfo.FSession, FBInfo, ErrString) = False Then
                        MsgBox(ErrString)
                        Return
                    End If
                Else
                    '--保存
                    If SControl._BILL_Cash_SaveBill(UInfo.FSession, FBInfo, ErrString) = False Then
                        MsgBox(ErrString)
                        Return
                    End If
                End If

                '-单号,验证码
                FBillNoBox.Text = FBInfo.FBillNo
                FVerifyBox.Text = FBInfo.FVerifyCode
                FMakerBox.Text = UInfo.FRName
                '--收费权限
                FSaveBox.Enabled = False
                If SControl._User_CheckAuth(UInfo.FSession, "BILL", "FCBILLVERIFYMY", "") Then
                    FSaveBox.Enabled = True
                    FSaveBox.Image = My.Resources.money
                    FSaveBox.Text = "收费"
                    FOpentype = "View"
                End If
                CHGControls(False)
            ElseIf FBInfo.FVid = Nothing And FBInfo.id > 0 Then
                '-审核
                FBInfo.FVid = UInfo.id
                FBInfo.FVName = UInfo.FRName
                If SControl._BILL_Cash_SaveBill(UInfo.FSession, FBInfo, ErrString) = False Then
                    MsgBox(ErrString)
                    Return
                End If
                FVermanBox.Text = FBInfo.FVName
                MsgBox("收费成功!")
                FSaveBox.Enabled = False
                FPrintBTN.Enabled = True
                Return
            Else
                MsgBox("参数错误")
                Dispose()
                Return
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
#End Region

    Private Sub FNameBox_SelectedIndexChanged(sender As Object, e As EventArgs)
        If FOpentype = "View" Then
            Return
        End If
        FCNameBox.SelectedValue = FNameBox.SelectedValue
    End Sub

    Private Sub FAmountBox_ValueChanged(sender As Object, e As EventArgs) Handles FAmountBox.ValueChanged
        If FOpentype = "View" Then
            Return
        End If
        FAmountBigBox.Text = FControl.MoneyToUpper(FAmountBox.Value)
    End Sub

    Private Sub FNameBox_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles FNameBox.SelectedIndexChanged
        If FOpentype = "View" Then
            Return
        End If
        Try
            FCNameBox.SelectedValue = FNameBox.SelectedValue
        Catch ex As Exception

        End Try
    End Sub
End Class